﻿Public Class frmDevolucionesBuscador

    Dim controller As New ControllerSigeco.controller_compras()
    Dim controllerStock As New ControllerSigeco.controller_stock

    Private _nroDevolucion As String = ""

    Public Property nroDevolucion() As String
        Get
            Return _nroDevolucion
        End Get
        Set(ByVal value As String)
            _nroDevolucion = value
        End Set
    End Property


    Private Sub frmComprasListado_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

        fechaInicio.Value = DateTime.Now.AddDays(-30)
        fechaFin.Value = DateTime.Now
        'oiml.CargarCombos(cboMotivo, "motivo", "idMotivoStock", controllerStock.get_motivos_stock(oiml.dbConn, True))
        dgCompras.AutoGenerateColumns = False
        CargarRemisiones()

    End Sub

    Private _conSaldo As Boolean = False

    Public Property conSaldo() As Boolean
        Get
            Return _conSaldo
        End Get
        Set(ByVal value As Boolean)
            _conSaldo = value
        End Set
    End Property

    Private _codCompra As Integer = 0

    Public Property codCompra() As Integer
        Get
            Return _codCompra
        End Get
        Set(ByVal value As Integer)
            _codCompra = value
        End Set
    End Property

    Private _codProveedor As Integer = 0

    Public Property codProveedor() As Integer
        Get
            Return _codProveedor
        End Get
        Set(ByVal value As Integer)
            _codProveedor = value
        End Set
    End Property

    Private _codDevolucion As Integer = 0

    Public Property codDevolucion() As Integer
        Get
            Return _codDevolucion
        End Get
        Set(ByVal value As Integer)
            _codDevolucion = value
        End Set
    End Property

    Private m_frmRemisiones As frmDevolucion
    Public Property frmRemisiones() As frmDevolucion
        Get
            Return m_frmRemisiones
        End Get
        Set(ByVal value As frmDevolucion)
            m_frmRemisiones = value
        End Set
    End Property

    Private Sub CargarRemisiones()

        Dim dt As New DataTable
        dt = controller.get_Remision_NotaCredito(oiml.dbConn, txtNroFactura.Text, fechaInicio.Value, fechaFin.Value, "", _
                                    "", 0, "", 0, codProveedor, codCompra, conSaldo)
        dgCompras.DataSource = dt

    End Sub

    Private Sub btnCancelar_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCancelar.Click

        Me.DialogResult = Windows.Forms.DialogResult.Cancel
        Me.Close()

    End Sub

    Private Sub btnEditar_Click()
        Try

            If dgCompras.SelectedRows.Count > 0 Then

                codDevolucion = dgCompras.SelectedRows(0).Cells(0).Value
                nroDevolucion = dgCompras.SelectedRows(0).Cells(1).Value
                Me.DialogResult = Windows.Forms.DialogResult.OK
                Me.Close()

            End If

        Catch ex As Exception
            MessageBox.Show("Error: " & ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error)

        End Try

    End Sub

    Private Sub txtBuscar_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txtBuscar.Click
        CargarRemisiones()
    End Sub

    Private Sub dgCompras_DoubleClick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles dgCompras.DoubleClick
        btnEditar_Click()
    End Sub

    Private Sub dgCompras_KeyDown(ByVal sender As System.Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles dgCompras.KeyDown
        If e.KeyCode = Keys.Enter Then
            btnEditar_Click()
        End If

    End Sub

End Class